package com.zbxj.wyz.controller;

import com.zbxj.wyz.domain.Choice;
import com.zbxj.wyz.domain.dto.ChoiceDto;
import com.zbxj.wyz.domain.dto.Result;
import com.zbxj.wyz.service.ChoiceService;
import com.zbxj.wyz.service.CourseService;
import com.zbxj.wyz.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Controller
@ResponseBody
public class ChoiceController {

    @Autowired
    ChoiceService choiceService;

    @Autowired
    CourseService courseService;

    @Autowired
    TypeService typeService;

    //添加选择题
    @PostMapping("/choice/add")
    public ResponseEntity addChoice(@RequestBody ChoiceDto choiceDto){
        int courseId = courseService.getIdByCourseName(choiceDto.getCourseName());
        int typeId = typeService.getIdByTypeName(choiceDto.getTypeName());
        Choice choice = choiceDto.toChioce(courseId,typeId, choiceDto);
        return ResponseEntity.ok(choiceService.addChoice(choice));
    }

    //删除选择题
    @PostMapping("/choice/delete")
    public ResponseEntity deleteChoice(@RequestBody Choice choice){
        return ResponseEntity.ok(choiceService.deleteChoice(choice));
    }

    //修改选择题
    @PostMapping("/choice/update")
    public ResponseEntity updateChoice(@RequestBody Choice choice){
        return ResponseEntity.ok(choiceService.updateChoice(choice));
    }

    // 审核选择题
    @PostMapping("/choice/audit")
    public ResponseEntity auditChoice(@RequestBody Choice choice){
        return ResponseEntity.ok(choiceService.auditChoice(choice));
    }

    @GetMapping("/choice/toexam/{courseName}/{choiceDifficulty}")
    public ResponseEntity getAllChoiceToExam(@PathVariable("courseName") String courseName,@PathVariable("choiceDifficulty") String choiceDifficulty){
        return ResponseEntity.ok(choiceService.getAllChoiceToExam(courseName,choiceDifficulty));
    }
}
